//  File:         Note.cpp
//  Author:       Scott Nordmann & Lauren Wallace
//  Description:  Non-inline member function definitions.
#include "Note.h"
#include <string>
#include <iostream>

using namespace std;
int Note::MIN_PRIORITY=1;
int Note::MAX_PRIORITY=5;

Note::Note(const string& creator, int prio): Entry(creator)
{
	setPriority(prio);
}
Note::Note(const string& creator,const string& titl, const string& cont, int prio): Entry(creator,titl,cont)
{
	setPriority(prio);
}

Note::~Note()
{
	
}


void Note::setPriority(int prio)
{
	if (prio <= MIN_PRIORITY)
		prio = MIN_PRIORITY;
	else if (prio >= MAX_PRIORITY)
		prio = MAX_PRIORITY;
	priority = prio;
}

//
//the user will chose a priority where low priority is the most important
//for our math and so that > and < will work we are converting it so that
//high numbers have the greatest priority
//
int Note::convertPriority(int prio) 
{
	return (MAX_PRIORITY - prio) + MIN_PRIORITY;
}


void Note::display() const
{
	cout << getTitle() << endl
		<< getContent() << endl
		<< "Priority:" << convertPriority(getPriority())
		<< " From: " << getCreatorName() << endl;
}

void Note::populate()
{
	Entry::populate();

	int prio = 0;

	cout << "Enter Priority (" << MIN_PRIORITY << " - " << MAX_PRIORITY << "): ";
	cin >> prio;
	cin.ignore();

	setPriority(convertPriority(prio));
}

void Note::edit()
{
	char command = ' ';
	string input;
	int prio;

	
	while (toupper(command) != 'N')
	{
		system("cls");
		display();

		cout << "Editing a Note" << endl << endl;
		
		cout << "T: Edit Title" << endl;
		cout << "C: Edit Content" << endl;
		cout << "P: Edit Priority" << endl << endl;
		cout << "N: No Changes" << endl << endl;
		
		cout << "Please enter your selection: ";
		cin >> command;
		cin.ignore();

		switch (toupper(command))
		{
		case 'T':
			cout << "New Title?: ";
			getline(cin, input);
			setTitle(input);
			break;
		
		case 'C':
			cout << "New Content?: ";
			getline(cin, input);
			setContent(input);
			break;
		
		case 'P':
			cout << "Enter New Priority (" << MIN_PRIORITY << " - " << MAX_PRIORITY << "): ";
			cin >> prio;

			setPriority(convertPriority(prio));
			break;
		
		case 'N':
			break;

		default:
			cout << "Invalid selection." << endl << endl;
			break;
		}
	}
}
ostream& operator<<(ostream& os, const Note& N)
{
    N.display();
    return os;
}
